package KFMmovie;

import java.io.File;
import java.util.Arrays;
import java.util.Objects;

public class User {
    private String username;
    private String phone;
    private String password;
    private int role;

    private Movie[] buyMovies = new Movie[10];
    private  int movieCount = 0;

    public User(String username, String phone, String password, int role) {
        this.username = username;
        this.phone = phone;
        this.password = password;
        this.role = role;
    }
    public User(){

    }


    public String getUsername() {
        return username;
    }

    public String getPhone() {
        return phone;
    }

    public String getPassword() {
        return password;
    }

    public int getRole() {
        return role;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setRole(int role) {
        this.role = role;
    }

    public Movie[] getBuyMovies() {
        return buyMovies;
    }

    public void setBuyMovies(Movie[] buyMovies) {
        this.buyMovies = buyMovies;
    }

    @Override
    public String toString() {
        return "User{" +
                "用户名：'" + username + '\'' +
                "，电话号码：" + phone + '\'' +
                "，密码：" + password +'\'' +
                "，身份：" +(role == 1 ? "管理员":"用户") +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        return role == user.role && Objects.equals(username, user.username)
                && Objects.equals(password, user.password)
                && Objects.equals(phone, user.phone);
    }
    public int hashCode(){
        return Objects.hash(username,phone,password,role);
    }

    /**
     * movie扩容
     */
    public void addMoive(Movie movie){
        buyMovies[movieCount ++] = movie;
    }
}
